package com.zhang.demo.spring;

import com.zhang.demo.spring.bean.Message;
import com.zhang.demo.spring.bean.User;
import com.zhang.demo.spring.bean.UserAttr;
import com.zhang.demo.spring.config.HelloWorld;
import com.zhang.demo.spring.config.JavaConfig;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * 到xml里取bean
 */
public class SpringHelloWord {


    public static void main(String[] args) {


        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("application.xml");

        User user = (User) applicationContext.getBean("user");

        System.out.println(user);

        Message message = (Message) applicationContext.getBean("message");

        System.out.println(message);

        User user2 = (User) applicationContext.getBean("user2");

        System.out.println(user2);


        UserAttr userAttr = (UserAttr) applicationContext.getBean("userAttr");

        System.out.println(userAttr);
        ApplicationContext configContext = new AnnotationConfigApplicationContext(JavaConfig.class);
        HelloWorld helloWorld = (HelloWorld) configContext.getBean("helloworld");

        helloWorld.sayHello();
    }



}
